@echo off
chcp 65001 >nul
echo ========================================
echo Reinstall Dependencies and Start System
echo ========================================
echo.

echo IMPORTANT: We have downgraded ethers.js from v6 to v5
echo This is to fix MetaMask connection issues
echo.

echo [1/3] Cleaning and reinstalling frontend dependencies...
cd frontend
if exist node_modules (
    echo Removing old node_modules...
    rmdir /s /q node_modules
)
if exist package-lock.json (
    echo Removing old package-lock.json...
    del package-lock.json
)
echo Installing dependencies (using ethers v5)...
call npm install
if %ERRORLEVEL% neq 0 (
    echo [ERROR] Frontend dependencies installation failed
    pause
    exit /b 1
)
echo [OK] Frontend dependencies installed successfully
echo.

echo [2/3] Checking blockchain dependencies...
cd ..\blockchain
if not exist node_modules (
    echo Installing blockchain dependencies...
    call npm install
)
echo [OK] Blockchain dependencies ready
echo.

echo [3/3] Checking backend dependencies...
cd ..\backend
echo [OK] Backend uses Maven, no additional installation needed
echo.

echo ========================================
echo Dependencies installation complete!
echo ========================================
echo.
echo You can now run start.bat to start the system
echo.
pause

